// const IP_PORT = "http://192.168.1.122:8901"
// const IP_PORT = "http://192.168.188.133:8901"
// const IP_PORT = "http://192.168.1.100:8901"
const IP_PORT = "https://www.dewcloud.net" // 默认443

App({

  data: {
    
  },

  onLaunch: function () {
    // if(wx.getStorageSync(userInfo)){
      
    // }
    // console.log(wx.getStorageSync(userInfo))

  },
  onShow: function () {
    // console.log('App Show')
  },
  onHide: function () {
    // console.log('App Hide')
  },
  //全局变量，要放在OnLaunch之后
  globalData: {
    hasLogin: false,
    code:"",
    session_key: "",
    cookie: "",
    cipherOpenid: "", // 目前就是明文的openid
    userInfo:{},
    queryAllURL: IP_PORT + "/origin/queryAll",
    queryTransList_U_URL: IP_PORT + "/origin/status/upload",
    queryTransList_D_URL: IP_PORT + "/origin/status/download",
    queryAllLogs_URL: IP_PORT + "/origin/history",
    uploadFileToHSB_URL: IP_PORT + "/upload",
    downloadFileFromHSB_URL: IP_PORT + "/download",
    clearMemoryFileInfo_URL: IP_PORT + "/clearTransedInfo",
    thumbnail_URL: IP_PORT + "/tmp",
    thumbnail_up_URL: IP_PORT + "/tmp/up",
    login_URL: IP_PORT + "/login",
  },

  getAlbumAuth: function () {
    //获取相册授权
    wx.getSetting({
      success(res) {
        console.log(res.authSetting['scope.writePhotosAlbum'])
        if (!res.authSetting['scope.writePhotosAlbum']) {
          wx.authorize({
            scope: 'scope.writePhotosAlbum',
            success() {
              console.log('授权成功')
            }
          })
        }
      }
    })
  },

  chooseTypeImage: function (type) {
    var image_type = 'image-unknown';
    switch(type) {
      case 'doc':
      case 'docx': image_type = 'image-word'; break;
      case 'txt': image_type = 'image-unknown'; break;
      case 'pdf': image_type = 'image-pdf'; break;
      case 'xls':
      case 'xlsx': image_type = 'image-excel'; break;
      case 'rar':
      case 'zip':
      case 'gz': image_type = 'image-rar'; break;
      case 'jpg': 
      case 'png':
      case 'jpeg': image_type = 'image-photo'; break;
      case 'ppt':
      case 'pptx': image_type = 'image-powerpoint'; break;
      case 'mp4':
      case 'avi': image_type = 'image-vedio'; break;
      default: image_type = 'image-unknown'; break;
    }
    return image_type;
  },

  convertByteSize: function (length) {
    if (length == null) {
      return "";
    }
    var size = length;
    //console.log('length:'+size)
    var unit = ["B","KB","MB","GB"];
    var index = 0; // index代表了unit的索引，默认是B
    while(size > 1000) {
      size = size / 1024; 
      index++;
    }
    //保留2位小数
    size = size.toFixed(2);
    return "" + size + unit[index]
  },

  convertTimeStamp: function (timestamp) {
    var len = timestamp.toString().length;
    // 时间戳为10位需*1000，时间戳为13位的话不需乘1000
    var date = new Date(timestamp);
    if (len === 10) {
      date = date * 1000;
    }
    var Y = date.getFullYear() + '-';
    var M =
      (date.getMonth() + 1 < 10
        ? '0' + (date.getMonth() + 1)
        : date.getMonth() + 1) + '-';
    var D = 
      (date.getDate() < 10
        ? '0' + date.getDate()
        : date.getDate()) + ' ';
    var h = 
      (date.getHours() < 10
        ? '0' + date.getHours()
        : date.getHours()) + ':';
    var m = 
      (date.getMinutes() < 10
        ? '0' + date.getMinutes()
        : date.getMinutes()) + ':';
    var s =
      (date.getSeconds()< 10
        ? '0' + date.getSeconds()
        : date.getSeconds());
    return Y + M + D + h + m + s; //2019-04-02 02:23:03


  },

  convertCloudProviderName: function (cloudName) {
    var cloudName_Chinese = null;
    switch(cloudName) {
      case 'baidu': cloudName_Chinese = '百度云'; break;
      case 'qiniu': cloudName_Chinese = '七牛云'; break;
      case 'jinshan': cloudName_Chinese = '金山云'; break;
      case 'ali': cloudName_Chinese = '阿里云'; break;
      case 'tengxun': cloudName_Chinese = '腾讯云'; break;

      default: cloudName_Chinese = '未知云'; break;
    }
    return cloudName_Chinese;
  },

  convertCode: function (code) {
    var status = '未知状态';
    switch (code) {
      case '101': status = '等待上传'; break;
      case '102': status = '正在上传'; break;
      case '103': status = '上传成功'; break;
      case '104': status = '上传成功'; break;
      // case '105': status = '腾讯云'; break;

      // case '100': status = '等待上传'; break;
      // case '101': status = '七牛云'; break;
      // case '102': status = '金山云'; break;
      // case '103': status = '阿里云'; break;
      // case '104': status = '腾讯云'; break;

      // case '100': status = '等待上传'; break;
      // case '101': status = '七牛云'; break;
      // case '102': status = '金山云'; break;
      // case '103': status = '阿里云'; break;
      // case '104': status = '腾讯云'; break;

      // case '100': status = '等待上传'; break;
      // case '101': status = '七牛云'; break;
      // case '102': status = '金山云'; break;
      // case '103': status = '阿里云'; break;
      // case '104': status = '腾讯云'; break;
      default: status = '未知状态'; break;
    }
    return status;
  },

  // convertPercent: function (point) {
  //   var point = 0.042
  //   var percent = Number(point * 100).toFixed(2);
  //   percent += "%";
  //   return percent;
  // }

})
